
/*

Dofile: table2_appendix.do 

Date: Dec. 10, 2016 
Aim: Stat des on the use of intra-firm exports  

Input: base_for_reg.dta 
Output: table2_appendix.dta 
Reported in the online appendix: "Table A.2: Intra-firm exports, by use"

*/  

cd $datapath

use "W:\research\data\Tax\Tax\cadre-b-c.dta" , clear
destring siren, replace force
drop if cadre==" "
drop if cadre==""
drop if cadre=="p"
drop if siren==0
drop if siren==46
drop if siren==1459
drop if siren==82001
replace cadre="Import" if cadre=="C"
replace cadre="Export" if cadre=="B"
keep if cadre=="Export"
drop if siren==.
sort siren
drop if extra<0
keep if intra>98 

g haven=0 
foreach x in LU CH IE HK CY SG MT BS BM KY{
replace haven=1 if  pays=="`x'" 
}

g nope=fab=="X"
egen tot =sum(montant) , by(nope)

foreach i in rev fab fin inv{
replace `i'="0" if `i'==""
}
tab rev if nope==0
tab fab if nope==0 
tab fin if nope==0 
tab inv if nope==0

tab rev if nope==0 & haven==1
tab fab if nope==0  & haven==1
tab fin if nope==0 & haven==1 
tab inv if nope==0 & haven==1

drop if nope==1 
g usage="R" if rev=="1" 
replace usage="Fa" if fab=="1"
replace usage="Fi" if fin=="1" 
replace usage="I" if inv=="1"
drop if usage=="" | usage==" "
collapse (sum) montant, by(haven usage)
egen tot=sum(montant) , by(haven) 
g sh=montant/tot 
sort usage haven 
egen tot_=sum(montant), by(usage) 
egen total=sum(montant) 
g sh_tot=tot_/total 
save table_appendix.dta, replace 


